﻿Imports System.Data.OleDb
Public Class PhieuNhapDAO
    Public Function GetPhieuNhap() As DataTable
        Dim sql As String = "select * from PhieuNhap"
        Dim dt As New DataTable
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim da As New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
    Public Sub AddPhieuNhap(ByVal newCC As PhieuNhapDTO)
        Dim sql As String = String.Format("insert into PhieuNhap(MaPhieu,ThoiGian,MaNV,NguoiGiao,NguyenLieu,TenNhaCungCap,TinhTrang,TongTien) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", _
                                           newCC.MaPhieu, newCC.NgayXuat, newCC.NguoiNhan, newCC.NguoiGiao, newCC.NguyenLieu, newCC.TenNhaCC, newCC.TinhTrang, newCC.TongTien)

        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Dữ liêu bị sai vui lòng kiểm tra lại !")
        End Try
        cn.Close()
    End Sub
    Public Sub DelPhieuNhap(ByVal delCC As PhieuNhapDTO)
        Dim sql As String = String.Format("delete from PhieuNhap where MaPhieu={0}", delCC.MaPhieu)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Sub UpdatePhieuNhap(ByVal newCC As PhieuNhapDTO)
        Dim sql As String = String.Format("update PhieuNhap set ThoiGian='{0}',MaNV='{1}',NguoiGiao='{2}',NguyenLieu='{3}',TenNhaCungCap='{4}',TinhTrang='{5}',TongTien='{6}' where MaPhieu={7}", _
                                          newCC.NgayXuat, newCC.NguoiNhan, newCC.NguoiGiao, newCC.NguyenLieu, newCC.TenNhaCC, newCC.TinhTrang, newCC.TongTien, newCC.MaPhieu)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Vui lòng kiểu tra lại dữ liệu !")
        End Try
        cn.Close()
    End Sub
End Class
